<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>候选人列表</title>  
</head>
<body>
<div class="ui segment" id="n-page">
&nbsp;<br>
&nbsp;<br>
<h3 class="ui attached header" id="list-title">
         系统推荐候选人列表
    </h3>
    <div class="ui attached segment" id="list-items">
    <c:forEach items="${emps}" var="emp">
         <div class="ui segment listitem2 position" data-position-id="${emp.id}">
            ${emp.name} ${emp.companyName}    ${emp.roleId}<br>
        </div>
    </c:forEach>    
    </div>
    <br>&nbsp;&nbsp;<br>

    <div class="ui segment" id="btn-next2">
        <div class="fluid ui button" id="more">更多候选人</div>
    </div>
   

</div>
<input type="hidden" name="lastperson" id="lastperson" value="${fn:length(emps)}"/>
<input type="hidden" name="hasmoredata" id="hasmoredata" value="yes"/> 
<input type="hidden" name="status" id="status" value="${position.status}"/>
<div class="ui segment" id="btn-next">
    <!--
    <div class="fluid ui button" id="next">编辑职位</div>
    -->
     <div class="ui button dog" id="closeit">回首页</div> 
    <div class="two ui buttons"> 
        
       
    </div>
</div>

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>
<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">

wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'showOptionMenu']  
});

    var handler = { 
        activate: function() { 
            $(this).addClass('active').siblings().removeClass('active'); 
            if($(this).attr('id') == 'more') {
                datasource.moredata();
            }
            

            if($(this).attr('id') == 'closeit') {
                wx.closeWindow();
            }
        } 
    };
    var datasource = { 
                      moredata: function() { 
                          var getUrl = '${ctx}/wechat/hunter/hr/moreJobRecommend.do?jobid='+${job.id};
                          var offset  = $('#lastperson').val();
                          var hasmore = $('#hasmoredata').val();

                          getUrl += "&offset=" + offset;

                          if(hasmore != "yes"){
                              alert("已经没有更多数据了");
                              return false;
                          }
                          var that = this;

                          $.ajax({ 
                                  url: getUrl, 
                                  type: "GET", 
                                  success: function(data, status){ 
                                      if(data.errorcode == 0) {
                                          that.appenddata(data);
                                      } else {
                                          var errorUrl = '${ctx}/wechat/headhunter/error.page';
                                          location.href = errorUrl;
                                      }
                                  }, 
                                  error: function(){ 
                                      alert("服务出错，请稍后尝试"); 
                                  } 
                          });
                      },

                      appenddata:function(data) { 
                          var offset = parseInt($('#lastperson').val());
                          var divstring = "";
                          var recommends = data.recommends;

                          var count = recommends.length;
                          offset += parseInt(count);
                          $('#lastperson').val(offset);
                          if(count <10) {
                              $('#hasmoredata').val('no');
                          }

                          for (var i in recommends) {
                              var rd = recommends[i];

                              divstring += '<div class="ui segment listitem2 position" data-position-id="'+ rd.id +'">';
                              divstring += rd.name;
                              divstring += ' ';
                              divstring += rd.companyname;
                              divstring += ' ';
                              divstring += rd.positionname;
                              divstring += '<br>';
                              if(rd.status == 0){
                              	divstring += '等待邀请';
                              }else if(rd.status == 1){
                              	divstring += '推荐中';
                              }else if(rd.status == 2){
                              	divstring += '推荐成功';
                              }else if(rd.status == 3){
                              	divstring += '推荐失败';
                              }else if(rd.status == 4){
                              	divstring += '被查看';
                              }else if(rd.status == 5){
                              	divstring += '有意向关注中';
                              }else if(rd.status == 6){
                              	divstring += '职位沟通确认';
                              }else if(rd.status==7){
                              	divstring += '同意职位沟通';
                              }else if(rd.status==8){
                              	divstring += '不同意职位沟通';
                              }
                              divstring += '</div>';
                          }

                          var newdata = $(divstring);
                          $('#list-items').append(newdata);
                      }
                  };
    $(document).ready(function() { 

        
            $('.button').on('click', handler.activate);
            
            $('.position').on('click', function() {
                var empid = $(this).attr('data-position-id');
                var getUrl = '${ctx}/wechat/hunter/hr/toViewCandidate.do?empid='+empid;
                location.href = getUrl;
            });
        
            var status  = $("#status").val();
            if(status >= 1) {
                $("#next").addClass('disabled');
            }
            wx.ready(function() {
<c:choose>
    <c:when test="${position.platformID == 2 }">
            wx.onMenuShareAppMessage({
                title: 'Headoffer--${position.name}--${position.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/sharejob.page?jobid=${position.id}',  
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg',  
                type: 'link'
            });

            wx.onMenuShareTimeline({
                title: 'Headoffer--${position.name}--${position.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/sharejob.page?jobid=${position.id}',  
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg'
            });
    </c:when>
    <c:otherwise>
            wx.onMenuShareAppMessage({
                title: '跳哪里--${position.name}--${position.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com/tn-candidate/wechat/candidate/sharejob.page?jobid=${position.id}',  
                imgUrl: 'http://www.tiaonali.com/tn-candidate/resources/images/sharelogo.jpg',  
                type: 'link'
            });

            wx.onMenuShareTimeline({
                title: '跳哪里--${position.name}--${position.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com/tn-candidate/wechat/candidate/sharejob.page?jobid=${position.id}',  
                imgUrl: 'http://www.tiaonali.com/tn-candidate/resources/images/sharelogo.jpg'
            });
    </c:otherwise>
</c:choose>
            wx.showOptionMenu();

        });

    });

</script>
</body>
</html>